package org.NooLab.glue.net.http.rest.resources;

import java.util.Map;

import org.restlet.representation.Representation;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;



public class StateResource extends ServerResource{

	long transactionID;  
	String tidStr ="";
	 
	Object transactionid; 
	/* 	this is mandatory for the resolution of the pathTemplate
	   	needs to be named EXACTLY like the string within the curly brackets (accolades) 
		as used in the attach statement for the router
		
		it will not throw an error, since (acc. to documentation of Restlet) the engine 
		is looking for the most similar path;
		yet, as the path will not be resolved correctly, the "value" remains unknown to the engine 
    */
	public StateResource() {

	 
	}

	 
	public void init() {
		
		tidStr = (String)getRequestAttributes().get("transactionid");
		
		transactionID = Long.parseLong(tidStr) ;
		
	}

	@SuppressWarnings("unused")
	@Get
	public String returnTransactionState() {
		
		String str="",tidStr;
		Representation entity=null;
		Map<String, Object> attr ;
		
		try{
			
			attr = getRequest().getAttributes() ;
			
			tidStr = (String) attr.get("transactionid");
			
		 
		
			str = "response by '"+this.toString()+"',state of transaction (ID \"" + tidStr + "\") : yet unknown..." ;
			
		} catch(Exception e){
			e.printStackTrace() ;
		}
		
		return str;
		
	}
	
}
